<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<c:if test="${canAddOrUpdate eq true}">
<div class="top-right-btn">
	<a href="user.pt">Create New User</a>
</div>
</c:if>

<br/>

<form:form action="users.pt" method="POST">
	<input type="hidden" name="action_value" id="idActionValue" value="" />
	
	<form:errors path="*" cssClass="error-message"/>
	
	<table class="input-table">
	<tbody>
		<tr>
			<td>User Type</td>
			<td>
				<form:select path="userType" onchange="doSubmit('action_type_select')" cssClass="element-select">
					<form:option value="" label=""/>
					<form:options items="${command.userTypes}" />
				</form:select>
			</td>
			<td>Role</td>
			<td>
				<form:select path="role" cssClass="element-select">
					<form:option value="" label=""/>
					<form:options items="${command.rolesByUserType}" />
				</form:select>
			</td>
			<td width="40%">
				&nbsp;
			</td>
		</tr>
		
		<c:if test="${command.userType == 'USER_ADMIN'}">
		<tr>
			<td></td>
			<td></td>
			<td></td><td></td>
			<td><input type="button" value="Show" name="action_btn_show" onclick="doSubmit('action_show')"/></td>
		</tr>
		</c:if>
		
		<c:if test="${command.userType == 'USER_STAFF'}">
		<tr>
			<td>Department</td>
			<td>
				<form:select path="department" cssClass="element-select">
					<form:option value="" label=""/>
					<form:options items="${departments}" itemValue="idAsString" itemLabel="name"/>
				</form:select>
			</td>
			<td></td>
			<td></td>
			<td><input type="button" value="Show" name="action_btn_show" onclick="doSubmit('action_show')"/></td>
		</tr>
		</c:if>
		
		<c:if test="${command.userType == 'USER_STUDENT'}">
		<tr>
			<td>Course</td>
			<td>
				<form:select path="course" cssClass="element-select" onchange="doSubmit('action_course_select')">
					<form:option value="" label=""/>
					<form:options items="${courses}" itemValue="idAsString" itemLabel="name"/>
				</form:select>
			</td>
			<td>Semester</td>
			<td>
				<form:select path="subCourse" cssClass="element-select">
					<form:option value="" label=""/>
					<form:options items="${semesters}" itemValue="idAsString" itemLabel="name"/>
				</form:select>
			</td>
			<td><input type="button" value="Show" name="action_btn_show" onclick="doSubmit('action_show')"/></td>
		</tr>
		</c:if>
	</tbody>
	</table>
</form:form>

<table class="list-results-table">
	<tbody>
		<tr>
			<th>Name</th>
			<th>Role</th>
			<th>Email</th>
			<th>Phone</th>
			<th width="10%">Created Date</th>
			<th width="15%">Last Updated Date</th>
		</tr>
		
		<c:forEach items="${users}" var="user">
		<tr>
			<td><a href="user.pt?id=<c:out value="${user.id}"/>"><c:out value="${user.name}"/></a></td>
			<td><c:out value="${roleMap[user.roleId]}"/></tD>
			<td><c:out value="${user.email}"/></td>
			<td><c:out value="${user.phoneNo}"/></td>
			<td>
				<fmt:formatDate value="${user.createdDate}" pattern="dd-MM-yyyy"/>
			</td>
			<td>
				<fmt:formatDate value="${user.lastUpdatedDate}" pattern="dd-MM-yyyy"/>
			</td>
		</tr>
		</c:forEach>
	</tbody>
</table>